import { defineStore } from 'pinia'
import AttrApi from '@/api/product/attr'
let useCategoryStore = defineStore('Category', {
  state: () => {
    return {
      //存储一级分类的数据
      c1Arr: [],
      //存储一级分类的ID
      c1Id: '',
      //存储二级分类的数据
      c2Arr: [],
      //存储二级分类的ID
      c2Id: '',
      //存储三级分类的数据
      c3Arr: [],
      //存储三级分类的ID
      c3Id: '',
    }
  },
  actions: {
    async getC1() {
      let result = await AttrApi.reqC1()
      // console.log('c1', result)
      if (result.code == 200) {
        this.c1Arr = result.data
        return 'ok'
      }
    },
    async getC2() {
      let result = await AttrApi.reqC2(this.c1Id)
      // console.log('c1', result)
      if (result.code == 200) {
        this.c2Arr = result.data
        return 'ok'
      }
    },
    async getC3() {
      let result = await AttrApi.reqC3(this.c2Id)
      // console.log('c1', result)
      if (result.code == 200) {
        this.c3Arr = result.data
        return 'ok'
      }
    },
  },
  getters: {},
})

export default useCategoryStore
